<!-- 父传子练习-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <chuan-di :arr="arr">
            <template slot="header" slot-scope="scope">
               <span>{{scope.wnm.city}}</span>
            </template>
        </chuan-di>
    </div>
    <script src="./js/vue.js"></script>
    <script>
        Vue.component('chuan-di',{
            props:{
                arr:{
                    type: Array,
                    required: true
                }
            },
            data:() => {
                return {
                   data: [
                    {  
                        city:'天津',
                    },
                    {
                        
                        city:'海南',
                    },
                    {   
                        city:'内蒙古'
                    },
                ]
                    }
            },
            methods:{
                handle(){
                   this.data.forEach(item => {
                       this.arr.push(item)
                   })
                }
            }
            ,
            template:`
                        <div>
                            <ul>
                              <li :key="item.id" v-for="item in arr">
                                <slot name="header" :wnm="item" />
                             </li>
                            </ul>
                            <button  @click="handle">添加</button>
                        </div>
                    `
        })
        const ve = new Vue({
            el:'#app',
            data:{
                arr:[]
            },
            mounted(){
                this.arr = [
                    {   id:1,
                        city:'长沙'
                    },
                    {
                        id:2,
                        city:'上海'
                    },
                    {
                        id:3,
                        city:'深圳'
                    },
                    {
                        id:4,
                        city:'北京'
                    },
                    {
                        id:5,
                        city:'云南'
                    }
                ]
            }
        })
    </script>
</body>
</html>